<?php
/**
	产品模块
*/
if(empty($_GET['sid']) && empty($_GET['cat'])){	?>
<ul style="margin:0;padding:0;display:table;width:100%;">
<?php
$sql="select * from ".DB_PREFIX."product_sub order by sort desc";
$query=mysql_query($sql);
$num_all=mysql_num_rows($query);
$page_size=9;
$page_count=ceil($num_all/$page_size);
$offset=$page_size*intval(!empty($_GET['page'])?($_GET['page']-1):0);
$sql="select * from ".DB_PREFIX."product_sub order by sort desc limit ".$offset." , ".$page_size;
$query=mysql_query($sql);
$num=mysql_num_rows($query);
if($num>0){
	while($arr=mysql_fetch_array($query)){
?>
	<li style="width:200px;height:150px;float:left;list-style-type:none;text-align:center;margin-left:7px;margin-bottom:20px;">
		<a href="
			<?php
			parse_str($_SERVER['QUERY_STRING'],$myArray);
			$myArray['sid']=$arr['id'];
			echo "./list.php?".http_build_query($myArray);
			?>
			">
			<img style="width:160px;" src="./admin/<?php  echo $arr['pic'];?>" border="0">
			<div style="text-align:center;height:20px;"><?php echo $arr['name']; ?></div>
		</a>
	</li>
<?php		
	}
}
?>
</ul>
<div style="text-align:center"><a href="<?php
	if(intval($_GET['page'])>1){
	parse_str($_SERVER['QUERY_STRING'],$myArray);
			$myArray['page']=$_GET['page']-1;
		echo "./list.php?".http_build_query($myArray);}?>
	">上一页</a>&nbsp;<a href="<?php
		if((intval($_GET['page'])<$page_count) && ($num_all>$page_size)){
		parse_str($_SERVER['QUERY_STRING'],$myArray);
			$myArray['page']=(empty($_GET['page'])?1:$_GET['page'])+1;
		echo "./list.php?".http_build_query($myArray);}?>
		">下一页</a>，<?php if(empty($page_count)){echo '0';}else{echo empty($_GET['page'])?1:intval($_GET['page']);} ?> / <?php echo $page_count; ?></div>
<?php	}elseif(!empty($_GET['sid'])){
$sql="select * from ".DB_PREFIX."product_sub where id=".intval($_GET['sid']);
$query=mysql_query($sql);
$num=mysql_num_rows($query);
if($num>0){
	$arr=mysql_fetch_array($query);
	echo "<p>".htmlspecialchars_decode($arr['description'])."</p>";
	}
}elseif(!empty($_GET['cat'])){
?>
<ul style="margin:0;padding:0;display:table;">
<?php
$sql="select * from ".DB_PREFIX."product_sub where category=".intval($_GET['cat'])." order by sort desc";
$query=mysql_query($sql);
$num_all=mysql_num_rows($query);
$page_size=9;
$page_count=ceil($num_all/$page_size);
$offset=$page_size*intval(!empty($_GET['page'])?($_GET['page']-1):0);
$sql="select * from ".DB_PREFIX."product_sub where category=".intval($_GET['cat'])." order by sort desc limit ".$offset." , ".$page_size;
$query=mysql_query($sql);
$num=mysql_num_rows($query);
if($num>0){
	while($arr=mysql_fetch_array($query)){
?>
	<li style="width:200px;height:150px;float:left;list-style-type:none;text-align:center;margin-left:7px;margin-bottom:20px;">
		<a href="
			<?php
			parse_str($_SERVER['QUERY_STRING'],$myArray);
			$myArray['sid']=$arr['id'];
			echo "./list.php?".http_build_query($myArray);
			?>
			">
			<img style="width:160px;" src="./admin/<?php  echo $arr['pic'];?>" border="0">
			<div style="text-align:center;height:20px;"><?php echo $arr['name']; ?></div>
		</a>
	</li>
<?php		
	}
  }	?>
 </ul>
 <div style="text-align:center"><a href="<?php
	if(intval($_GET['page'])>1){
	parse_str($_SERVER['QUERY_STRING'],$myArray);
			$myArray['page']=$_GET['page']-1;
		echo "./list.php?".http_build_query($myArray);}?>
	">上一页</a>&nbsp;<a href="<?php
		if((intval($_GET['page'])<$page_count) && ($num_all>$page_size)){
		parse_str($_SERVER['QUERY_STRING'],$myArray);
			$myArray['page']=(empty($_GET['page'])?1:$_GET['page'])+1;
		echo "./list.php?".http_build_query($myArray);}?>
		">下一页</a>，<?php if(empty($page_count)){echo '0';}else{echo empty($_GET['page'])?1:intval($_GET['page']);} ?> / <?php echo $page_count; ?></div>
<?php }else{}	?>